import * as echarts from '../../component/ec-canvas/echarts';
import geoJson from '../../utils/mapData'

function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr 
  });
  canvas.setChart(chart);
  echarts.registerMap('china', geoJson);

  const option = {
    tooltip: {
      trigger: 'item',
      triggerOn:"mousemove",
      formatter:function(e){
        console.log(e.data.name);
        wx.navigateTo({
          url:`./../province/provice?name=${e.data.name}&value=${e.data.value}`
        })}
      },
    visualMap: {
      type:'continuous',
      min: 0,
      max: 100,
      left: 'left',
      top: 'bottom',
      show:false
    },
    series: [{
      type: 'map',
      zoom:1.2,
      mapType: 'china',
      label: {
        normal: {
          show:false //在省市区是否显示省市区名称
        },
        emphasis: {
          textStyle: {
            color: '#333'
          }
        }
      },
      itemStyle: {
        normal: {
          borderColor: '#389BB7',
          areaColor: '#fff',
        },
        emphasis: {
          areaColor: '#389BB7',
          borderWidth: 0
        }
      },
      animation: false,
      data: [ 
        { name: '北京市', value: 100 },
        { name: '天津市', value: 10 },
        { name: '上海市', value: 11 },
        { name: '重庆市', value: 12 },
        { name: '内蒙古自治区', value: 13 },
        { name: '广西壮族自治区', value: 64 },
        { name: '西藏自治区', value: 15 },
        { name: '宁夏回族自治区', value: 16 },
        { name:'新疆维吾尔自治区',value: 17 },
        { name: '香港特别行政区', value: 18 },
        { name: '澳门特别行政区', value: 19 },
        { name: '河北省', value: 20 },
        { name: '山西省', value: 21 },
        { name: '辽宁省', value: 22 },
        { name: '吉林省', value: 23 },
        { name: '黑龙江省', value: 24 },
        { name: '江苏省', value: 25 },
        { name: '浙江省', value: 26 },
        { name: '安徽省', value: 27 },
        { name: '福建省', value: 28 },
        { name: '江西省', value: 29 },
        { name: '山东省', value: 30 },
        { name: '河南省', value: 31 },
        { name: '湖北省', value: 32 },
        { name: '湖南省', value: 1 },
        { name: '广东省', value: 2 },
        { name: '海南省', value: 5 },
        { name: '四川省', value: 6 },
        { name: '贵州省', value: 7 },
        { name: '云南省', value: 8 },
        { name: '陕西省', value: 9 },
        { name: '甘肃省', value: 3 },
        { name: '青海省', value: 14 },
        { name: '台湾省', value: 42 }
      ]
    }],
  };
  chart.setOption(option);
  return chart;
}


Page({
	data:{
			ec: {
			      onInit: initChart
			    }
    },
})